package com.win.oauth.mapper;

import com.win.oauth.dto.ModulePermissionDTO;
import com.win.oauth.entity.Module;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author youlian.fei
 * @since 2020-03-14
 */
public interface ModuleMapper extends BaseMapper<Module> {

    @Select({"SELECT module.*, perm.id AS perm_id, perm.url FROM sys_module module ",
            " LEFT JOIN sys_permission perm ON perm.type = 1 AND perm.module_fun_id = module.id",
            " ORDER BY module.seq ASC, module.id ASC "})
    List<ModulePermissionDTO> selectListDTO();


    @Select({"SELECT module.*, perm.id AS perm_id, perm.url FROM sys_module module ",
            " LEFT JOIN sys_permission perm ON perm.type = 1 AND perm.module_fun_id = module.id",
            " WHERE module.id = #{id}"})
    ModulePermissionDTO getById(@Param("id") Long id);
}
